<?
/*
 * Copyright (c) 2010 DC Team
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files(the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

define('DC', true);
include_once('../common.php');

//获取远程数据
$domain = $configs['domain'].'/';
$data = file_get_contents('http://'.$_REQUEST['domain'].'/'.$domain.'dataout.php?act=myequip&dbId='.$_REQUEST['dbId']);

if (!$data) {
	exit('获取数据失败，请检查设置是否正确');
}
//对比操作
if (!get_magic_quotes_gpc()) {
	$data = stripslashes($data);	
}

$data = unserialize( base64_decode($data) );
$_SESSION['netcom']['netdata'] = $data;//用于字段对步

//获取数据库相关信息
$dbmainId    = $_POST['dbmainId'];
$g_db        = mysqlConnect($dbmainId);
$maindataArr = checkDatabase($dbmainId);
$dbdataArr   = $data;

$diffenArr = compareNetDb ($dbdataArr, $maindataArr, $dbmainId);

//输出比较的结果
$html = "<div align=center><input type='checkbox' id='is_back' name='is_back' value='1' checked><font color=red >是否备份</font>&nbsp;&nbsp;<b>主数据库为:{$dbmainId},以下为选中数据库的比较结果</b></div>";
foreach ($diffenArr as $key => $value){
	$html .= "<form><table width=\"800\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"myTable\"><tr><th><input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this.form)' value='checkbox'> 全选</th><th>表名</th><th>数据库<font color=red>{$key}</font></th><th>字段缺少</th><th>字段多余</th></tr>";
	foreach ($value as $k => $val){
		//是否显示同步按钮
		$button = 1;
		if ($val['exist'] == '完全一致') {
			$button = 0;
		}
		if ($val['exist'] != '存在') {
			$str = '<font color=red>'.$val['exist'].'</font>';
		}else {
			$str = $val['exist'];
		}
		$html .= "<tr><td><input type='checkbox' name='dbids_{$key}' value='{$k}' /></td><td>{$k}</td><td>{$str}</td><td>{$val['lack']}</td><td>{$val['more']}</td></tr>";
	}
	$html .= "<tr><td colspan='6'>[数据库{$key}]&nbsp;&nbsp;";
	$html .= "<a href='#' onclick=\"if(confirm('确定将远程多余字段同步回本地吗?')) asynNetDb('netfield', '{$key}', '{$dbmainId}');\">同步字段</a> &nbsp;&nbsp;";
	$html .= "</td></tr></table></form></div>";
}
echo $html;


?>